<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>promise学习</title>

    <body>
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <script>
            //#region promise AJAX请求
            const p = new Promise((resolve,reject)=>{
                $.ajax({
                type: "GET",
                url: "https://api.apiopen.top/getJoke",
                success: function (data) {
                    //成功
                    resolve(data);
                },
                error: function (xhr) {
                    //失败
                    reject(xhr.status);
                }
              });
            });

            p.then(function(value){
                console.log(value);
            },function(reason){
                console.error(reason);
            });
           //#endregion

           
        </script>



    </body>
</head>
</html>